package com.px.auditRecord.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.px.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.px.framework.aes.AesSecurityParameter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.px.common.annotation.Log;
import com.px.common.core.controller.BaseController;
import com.px.common.core.domain.AjaxResult;
import com.px.common.enums.BusinessType;
import com.px.auditRecord.domain.RoutesBasic;
import com.px.auditRecord.service.IRoutesBasicService;
import com.px.common.utils.poi.ExcelUtil;
import com.px.common.core.page.TableDataInfo;

/**
 * hangxianController
 * 
 * @author WRJ
 * @date 2024-08
 */
@Api("hangxian")
@RestController
@RequestMapping("/routes/basic")
public class RoutesBasicController extends BaseController
{
    @Autowired
    private IRoutesBasicService routesBasicService;

    /**
     * 查询hangxian列表
     */
    @ApiOperation("查询hangxian列表")
    @PreAuthorize("@ss.hasPermi('routes:basic:query')")
    @GetMapping("/list")
    @AesSecurityParameter(outEncode = true)
    public TableDataInfo list(RoutesBasic routesBasic)
    {
        startPage();
        List<RoutesBasic> list = routesBasicService.selectRoutesBasicList(routesBasic);
        return getDataTable(list);
    }

    /**
     * 导出hangxian列表
     */
    @ApiOperation("导出hangxian列表")
    @PreAuthorize("@ss.hasPermi('routes:basic:query')")
    @Log(title = "hangxian", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @AesSecurityParameter(outEncode = false)
    public void export(HttpServletResponse response, RoutesBasic routesBasic)
    {
        List<RoutesBasic> list = routesBasicService.selectRoutesBasicList(routesBasic);
        ExcelUtil<RoutesBasic> util = new ExcelUtil<RoutesBasic>(RoutesBasic.class);
        util.exportExcel(response, list, "hangxian数据");
    }

    /**
     * 获取hangxian详细信息
     */
    @ApiOperation("获取hangxian详细信息")
    @GetMapping(value = "/{id}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(routesBasicService.selectRoutesBasicById(id));
    }

    /**
     * 新增hangxian
     */
    @ApiOperation("新增hangxian")
    @PreAuthorize("@ss.hasPermi('routes:basic:edit')")
    @Log(title = "hangxian", businessType = BusinessType.INSERT)
    @PostMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult add(@RequestBody RoutesBasic routesBasic)
    {
        return toAjax(routesBasicService.insertRoutesBasic(routesBasic));
    }

    /**
     * 修改hangxian
     */
    @ApiOperation("修改hangxian")
    @PreAuthorize("@ss.hasPermi('routes:basic:edit')")
    @Log(title = "hangxian", businessType = BusinessType.UPDATE)
    @PutMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult edit(@RequestBody RoutesBasic routesBasic)
    {
        return toAjax(routesBasicService.updateRoutesBasic(routesBasic));
    }

    /**
     * 新增hangxian
     */
    @ApiOperation("个人新增航线库")
    @PostMapping("/flightAdd")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult flightAdd(@RequestBody RoutesBasic routesBasic)
    {
        routesBasic.setCreateBy(getUserId().toString());
        routesBasic.setCreateTime(DateUtils.getNowDate());
        return toAjax(routesBasicService.insertRoutesBasic(routesBasic));
    }

    @ApiOperation("个人新增航线库")
    @PutMapping("/flightEdit")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult flightEdit(@RequestBody RoutesBasic routesBasic)
    {
        routesBasic.setUpdateBy(getUserId().toString());
        routesBasic.setUpdateTime(DateUtils.getNowDate());
        return toAjax(routesBasicService.updateRoutesBasic(routesBasic));
    }

    @ApiOperation("个人删除航线库")
    @DeleteMapping("/{ids}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult flightRemove(@PathVariable Integer[] ids)
    {
        routesBasicService.deleteRoutesBasicByIds(ids);
        return success();
    }

    @ApiOperation("查询hangxian列表")
    @GetMapping("/flightList")
    @AesSecurityParameter(outEncode = true)
    public TableDataInfo flightList(RoutesBasic routesBasic)
    {
        startPage();
        routesBasic.setCreateBy(getUserId().toString());
        List<RoutesBasic> list = routesBasicService.selectRoutesBasicList(routesBasic);
        return getDataTable(list);
    }

}
